{extend name="layout/base"}
{block name="title"}添加分类{/block}
{block name="main"}
<div class="right-main">
    <div class="mdui-card border-1 mdui-shadow-0 mdui-m-b-2 ">
        <div class="mdui-card-primary">
            <h3>添加分类</h3>
        </div>
        <div class="mdui-divider "></div>
        <div class="mdui-card-content">
            <form action="" class="layui-form ">
                <div class="mdui-textfield mdui-p-l-2">
                    <div class="mdui-textfield-label">名称</div>
                    <input name="name" class="mdui-textfield-input" type="text" />
                </div>
                <div class="mdui-textfield mdui-p-l-2">
                    <div class="mdui-textfield-label">排序</div>
                    <input name="sort" placeholder="数小靠前 不填为1" class="mdui-textfield-input" type="text" >
                </div>
                <div class="mdui-textfield mdui-p-l-2">
                    <div class="mdui-textfield-label mdui-m-b-1">是否显示</div>
                    <input type="checkbox" value="1" name="state" lay-text="开启|关闭" lay-skin="switch">

                </div>
                <div class="mdui-textfield mdui-p-l-2">
                    <button class="mdui-btn border-1" lay-submit lay-filter="submit">提交</button>
                </div>
            </form>
        </div>

    </div>
</div>

{/block}
{block name="script"}
<script>
    layui.use('form', () => {
        var form = layui.form, layer = layui.layer, $ = layui.jquery;
        form.on('submit(submit)', data => {
            $.post('/admin/cate', data.field, res => {
                if (res.code === 1) {
                    layer.msg(res.msg, {icon: 6, time: 1500}, () => {
                        location.href = res.url
                    })
                } else {
                    layer.msg(res.msg, {icon: 5, anim: 2, time: 1500}, () => {
                        // location.reload()
                    })
                }
            })
            return false;
        })
    })
</script>
{/block}